﻿function StatusListItemModel(id, createdAt, text, customerId, deleted, customerName, customerLogoUrl, customerEmail, pics, isProduct, productStock, productPrice, productId, tags) {


    var self = this;
    self.Id = ko.observable(id);
    self.Text = ko.observable(text);
    self.CustomerId = ko.observable(customerId);
    self.Deleted = ko.observable(deleted);
    self.CustomerName = ko.observable(customerName);
    self.CustomerLogoUrl = ko.observable(customerLogoUrl);
    self.CustomerEmail = ko.observable(customerEmail);
    self.Pics = ko.observableArray(pics);
    self.Tags = ko.observableArray(tags);
    self.IsProduct = ko.observable(isProduct);
    self.ProductStock = ko.observable(productStock);
    self.ProductPrice = ko.observable(productPrice);
    self.ProductId = ko.observable(productId);

    self.GoOnePageProduct = function (p, event) {
        var link = "/status/" + p.Id();


        var target = event.target;
        if (target.nodeName == "IMG") {
            return false;
        } else {
            location.href = link;
        }
    };
}


function StatusPictureModel(picId, picUrl) {

    var self = this;
    self.PicId = ko.observable(picId);
    self.PicUrl = ko.observable(picUrl);
    self.IsOrignalSize = ko.observable(false);
    self.PicSize = ko.observable(80);

    self.ShowOriginalPic = function () {

        if (self.IsOrignalSize() == true) {
            self.IsOrignalSize(false);
            self.PicSize(80);
            $.ajax({
                url: "/api/PicApi/GetPicUrl",
                type: 'post',
                data: ko.toJSON(self),
                contentType: 'application/json',
                success: function (result) {

                    self.PicUrl(result.PicUrl);
                }
            });
        } else {
            self.IsOrignalSize(true);
            self.PicSize(0);
            $.ajax({
                url: "/api/PicApi/GetPicUrl",
                type: 'post',
                data: ko.toJSON(self),
                contentType: 'application/json',
                success: function (result) {

                    self.PicUrl(result.PicUrl);
                }
            });
        }

    };
}